#include<iostream>
#include<unistd.h>
#include<vector>
#include"Thread.h"

pthread_mutex_t _mutex=PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t _cond=PTHREAD_COND_INITIALIZER;

void Print()
{
    pthread_mutex_lock(&_mutex);
    while(true)
    {
        std::cout<<"i am thread: "<<pthread_self()<<std::endl;
        //sleep(1)
        pthread_cond_signal(&_cond);
        pthread_cond_wait(&_cond,&_mutex);
    }
    pthread_mutex_unlock(&_mutex);
}

int main()
{
    std::vector<Thread> threads;
    threads.reserve(2);
    int i=2;
    while(i--)
    {
        threads.push_back(Thread(Print,"thread"+std::to_string(i)));
        threads.back().Start();
    }

    for(auto& e:threads)
    {
        e.Wait();
    }

    return 0;
}